package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppAuth;
import com.vf.admin.miaodong.entity.AppPriceSet;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AppPriceSetDao extends BaseDao<AppPriceSet> {

    public List<AppPriceSet> page(Map<String, Object> params, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_price_set where 1=1");

        if(params.containsKey("type") && StringEx.isNotNull(params.get("type"))) {
            sbStr.append(" and type = ? ");
            paramList.add(params.get("type"));
        }

        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppPriceSet.class, splitPage);
    }

    public AppPriceSet info(Integer id) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_price_set where id = ? ");
        paramList.add(id);

        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppPriceSet.class);
    }

    public void del(Integer id) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("delete from app_price_set where id = ? ");
        paramList.add(id);

        String sql = sbStr.toString();
        this.del(sql, paramList);
    }

    public List<AppPriceSet> typeList() {
        StringBuilder sbStr = new StringBuilder("select * from app_price_set order by price asc ");

        String sql = sbStr.toString();
        return this.queryList(sql, new ArrayList(), AppPriceSet.class);
    }

    public AppPriceSet maxPriceNoCharm(Integer type) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_price_set where type = ? and charmLevel = 0 order by price desc ");
        paramList.add(type);

        String sql = sbStr.toString();
        List<AppPriceSet> list = this.queryList(sql, paramList, AppPriceSet.class);

        return list.size() > 0 ? list.get(0) : new AppPriceSet();
    }

    public AppPriceSet lowPriceNoCharm(Integer type) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_price_set where type = ? and charmLevel = 0 order by price asc ");
        paramList.add(type);

        String sql = sbStr.toString();
        List<AppPriceSet> list = this.queryList(sql, paramList, AppPriceSet.class);

        return list.size() > 0 ? list.get(0) : new AppPriceSet();
    }

    public AppPriceSet infoByTypeAndPrice(Integer type, String price) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_price_set where type = ? and price = ?");
        paramList.add(type);
        paramList.add(price);

        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppPriceSet.class);
    }
}
